package cn.wolfcode.ssm.controller;

import cn.wolfcode.ssm.domain.Permission;
import cn.wolfcode.ssm.qo.JsonResult;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

   @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")QueryObject qo) {
        PageInfo<Permission> pageInfo = permissionService.selectForPageResult(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "permission/list";
    }


    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
            permissionService.delete(id);
        }
        return "redirect:/permission/list.do";
    }

    @RequestMapping("/reload")
    @ResponseBody
    public JsonResult reload() {
            permissionService.reload();
            return new JsonResult();
    }
}
